<?php
#添加新注册用户信息
session_start();
include "connect.php";
$name = $_POST['name'];
$password = $_POST['password'];
$telephone = $_POST['telephone'];
$captcha = $_POST['captcha'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$time = date('Y-m-d',time());

if($captcha == $_SESSION['captcha']){
    $query = "select * from tb_user where username = '$name'";
    $result = mysqli_query($link,$query);
    if(mysqli_num_rows($result) > 0){
        echo '<script>alert("用户名已存在请重新输入！！！")</script>';
        echo '<script>location.href = "register.php"</script>';
    }else{
        if($password == ''){
            echo '<script>alert("密码不能为空！！！")</script>';
            echo '<script>location.href = "register.php"</script>';
        }else{
            $query2 = "insert into tb_user values ('','$name','$password','$mail','$telephone','$address','$time')";
            $result2 = mysqli_query($link,$query2);
            if(mysqli_affected_rows($link) > 0){
                header('location:login.php');
            }else{
                echo '<script>alert("注册失败！！！")</script>';
                echo '<script>location.href = "register.php"</script>';
            }
        }
    }
}else{
    echo '<script>alert("验证码输入错误！！！")</script>';
    echo '<script>location.href = "register.php"</script>';
}
